package com.tsn.controller;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.tsn.common.Result;
import com.tsn.entity.Event;
import com.tsn.entity.Media;
import com.tsn.service.EventService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

/**
 * <p>
 * 游记 前端控制器
 * </p>
 *
 * @author tsn
 * @since 2021-08-13
 */
@RestController
@RequestMapping("/tsn/event")
public class EventController {

    @Autowired
    private EventService eventService;

    @GetMapping("/getEvents")
    private Result getEvents(){
        return Result.success(eventService.list());
    }
    @PostMapping("/addEvent")
    private Result addEvent(@RequestBody JSONObject object){
        Event event = JSON.toJavaObject(object, Event.class);
        String substring = event.getEventTime().substring(0, 4);
        String s = String.valueOf(Integer.parseInt(substring) + 1);
        event.setEventTime(s);
        eventService.save(event);
        return Result.success(null);

    }


}

